package eerbaar.v2.app.view2;

import java.awt.Point;

import eerbaar.shared.service.ServiceFactory;
import eerbaar.v2.app.mouse.IMouseListener;
import eerbaar.v2.app.mouse.MouseEvent2;
import eerbaar.v2.app.mover.IPersonaMover;
import eerbaar.v2.app.view.IView;
import eerbaar.v2.app.view.Square;
import eerbaar.v2.app.view.Squares;

public class PersonaMouse implements IMouseListener {

    private final IView view;

    public PersonaMouse(IView view) {
        this.view = view;
    }

    @Override
    public void mouseClicked(MouseEvent2 event) {

        Squares squares = this.view.getSquares();
        Point point = new Point(event.getX(), event.getY());
        Square square = squares.getSquare(point);

        if (square == null) {
            return;
        }

        IPersonaMover mover = ServiceFactory.getService(IPersonaMover.class);
        if (mover != null) {
            mover.moveTo(square.getX(), square.getY());
        }
    }

    @Override
    public void mouseExited() {
        //
    }

    @Override
    public void mouseMoved(MouseEvent2 e) {
        //
    }

}
